package com.fjnu.dao.impl;

import com.fjnu.dao.TagDao;
import com.fjnu.entity.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class TagDaoImpl implements TagDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public int insert(Tag tag) {
        String sql = "INSERT INTO tb_tag (name,create_time,update_time) VALUES (?,?,?)";
        int result = jdbcTemplate.update(sql,
                tag.getName(),
                tag.getCreateTime(),
                tag.getUpdateTime());
        return result > 0 ? 1 : 0;

    }

    @Override
    public int insertArticleTag(Integer articleId, Integer tagId) {
        String sql = "INSERT INTO tb_article_tag (article_id,tag_id) VALUES (?,?)";
        int result = jdbcTemplate.update(sql,
                articleId,
                tagId);
        return result > 0 ? 1 : 0;
    }
}
